﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class NonTermCurrentDBAccess
    {
        /// <summary>
        /// Insert NonTermCurrent
        /// </summary>
        /// <param name="objNonTerm"></param>
        /// <param name="CONNECTION_STRING"></param>
        /// <returns></returns>
        public bool AddNewNonTermCurrent(NonTermCurrent objNonTerm, String CONNECTION_STRING)
        {
            SqlParameter[] parameters = new SqlParameter[]
            {                
                new SqlParameter("@Created", objNonTerm.Created),
                new SqlParameter("@Updated",objNonTerm.Updated),
                new SqlParameter("@Isactive", objNonTerm.Isactive),
                new SqlParameter("@AccountNumber", objNonTerm.AccountNumber),
                new SqlParameter("@UserID", objNonTerm.UserID),
                new SqlParameter("@Opendate", objNonTerm.Opendate),
                new SqlParameter("@Balance", objNonTerm.Balance),
                new SqlParameter("@Currency", objNonTerm.Currency),
                new SqlParameter("@InterestRateID", objNonTerm.InterestRateID),
                new SqlParameter("@LocationID", objNonTerm.LocationID),
                new SqlParameter("@Status", objNonTerm.Status),
                new SqlParameter("@Descriptions", objNonTerm.Descriptions),
                new SqlParameter("@AccountHolders", objNonTerm.AccountHolders)
            };

            return SqlDBHelper.ExecuteNonQuery("AddNewNonTermCurrent", CommandType.StoredProcedure, CONNECTION_STRING, parameters);
        }

        /// <summary>
        /// Update NonTermCurrent
        /// </summary>
        /// <param name="objNonTerm"></param>
        /// <param name="CONNECTION_STRING"></param>
        /// <returns></returns>
        public bool UpdateNonTermCurrent(NonTermCurrent objNonTerm, String CONNECTION_STRING)
        {
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@NonTermCurrentID", objNonTerm.NonTermCurrentID),
                new SqlParameter("@Created", objNonTerm.Created),
                new SqlParameter("@Updated",objNonTerm.Updated),
                new SqlParameter("@Isactive", objNonTerm.Isactive),
                new SqlParameter("@AccountNumber", objNonTerm.AccountNumber),
                new SqlParameter("@UserID", objNonTerm.UserID),
                new SqlParameter("@Opendate", objNonTerm.Opendate),
                new SqlParameter("@Balance", objNonTerm.Balance),
                new SqlParameter("@Currency", objNonTerm.Currency),
                new SqlParameter("@InterestRateID", objNonTerm.InterestRateID),
                new SqlParameter("@LocationID", objNonTerm.LocationID),
                new SqlParameter("@Status", objNonTerm.Status),
                new SqlParameter("@Descriptions", objNonTerm.Descriptions),
                new SqlParameter("@AccountHolders", objNonTerm.Descriptions)
            };

            return SqlDBHelper.ExecuteNonQuery("UpdateNonTermCurrent", CommandType.StoredProcedure, CONNECTION_STRING, parameters);
        }

        /// <summary>
        /// Delete NonTermCurrent
        /// </summary>
        /// <param name="NonTermCurrentID"></param>
        /// <param name="CONNECTION_STRING"></param>
        /// <returns></returns>
        public bool DeleteNonTermCurrent(int NonTermCurrentID, String CONNECTION_STRING)
        {
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@NonTermCurrentID", NonTermCurrentID)
            };

            return SqlDBHelper.ExecuteNonQuery("DeleteNonTermCurrent", CommandType.StoredProcedure, CONNECTION_STRING, parameters);
        }

        /// <summary>
        /// Get Non Term Current Details
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="CONNECTION_STRING"></param>
        /// <returns></returns>
        public NonTermCurrent GetNonTermCurrentDetails(int UserID, String CONNECTION_STRING)
        {
            NonTermCurrent objNonTerm = null;

            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@UserID",UserID),
            };
            //Lets get the list of all Non Term Current in a datataable
            using (DataTable table = SqlDBHelper.ExecuteParamerizedSelectCommand("GetNonTermCurrentDetails", CommandType.StoredProcedure, CONNECTION_STRING, parameters))
            {
                //check if any record exist or not
                if (table.Rows.Count == 1)
                {
                    DataRow row = table.Rows[0];

                    //Lets go ahead and create the list of Non Term Current
                    objNonTerm = new NonTermCurrent();

                    //Now lets populate Non Term Current details into the list of Non Term Current                                          
                    objNonTerm.NonTermCurrentID = Convert.ToInt32(row["NonTermCurrentID"]);
                    objNonTerm.Created = row["Created"].ToString();
                    objNonTerm.Updated = row["Updated"].ToString();
                    objNonTerm.Isactive = row["Isactive"].ToString();
                    objNonTerm.AccountNumber = row["AccountNumber"].ToString();
                    objNonTerm.UserID = Convert.ToInt32(row["UserID"].ToString());
                    objNonTerm.Opendate = row["Opendate"].ToString();
                    objNonTerm.Balance = Convert.ToDouble(row["Balance"].ToString());
                    objNonTerm.Currency = row["Currency"].ToString();
                    objNonTerm.InterestRateID = Convert.ToInt32(row["InterestRateID"].ToString());
                    objNonTerm.LocationID = Convert.ToInt32(row["LocationID"].ToString());
                    objNonTerm.Status = row["Status"].ToString();
                    objNonTerm.Descriptions = row["Descriptions"].ToString();
                    objNonTerm.AccountHolders = row["AccountHolders"].ToString();
                }
            }

            return objNonTerm;
        }


        /// <summary>
        /// Get Non Term Current List
        /// </summary>
        /// <param name="CONNECTION_STRING"></param>
        /// <returns></returns>
        public List<NonTermCurrent> GetNonTermCurrentList( String CONNECTION_STRING)
        {
            List<NonTermCurrent> listNonTermCurrent = null;
            //Lets get the list of all Non Term Current in a datataable
            using (DataTable table = SqlDBHelper.ExecuteSelectCommand("GetNonTermCurrentList", CommandType.StoredProcedure, CONNECTION_STRING))
            {
                //check if any record exist or not
                if (table.Rows.Count > 0)
                {
                    //Lets go ahead and create the list of Non Term Current
                    listNonTermCurrent = new List<NonTermCurrent>();

                    //Now lets populate Non Term Current details into the list of Non Term Current
                    foreach (DataRow row in table.Rows)
                    {
                        NonTermCurrent objNonTerm = new NonTermCurrent();
                        objNonTerm.NonTermCurrentID = Convert.ToInt32(row["NonTermCurrentID"]);
                        objNonTerm.Created = row["Created"].ToString();
                        objNonTerm.Updated = row["Updated"].ToString();
                        objNonTerm.Isactive = row["Isactive"].ToString();
                        objNonTerm.AccountNumber = row["AccountNumber"].ToString();
                        objNonTerm.UserID = Convert.ToInt32(row["UserID"].ToString());
                        objNonTerm.Opendate = row["Opendate"].ToString();
                        objNonTerm.Balance = Convert.ToDouble(row["Balance"].ToString());
                        objNonTerm.Currency = row["Currency"].ToString();
                        objNonTerm.InterestRateID = Convert.ToInt32(row["InterestRateID"].ToString());
                        objNonTerm.LocationID = Convert.ToInt32(row["LocationID"].ToString());
                        objNonTerm.Status = row["Status"].ToString();
                        objNonTerm.Descriptions = row["Descriptions"].ToString();
                        objNonTerm.AccountHolders = row["AccountHolders"].ToString();
                        listNonTermCurrent.Add(objNonTerm);
                    }
                }
            }

            return listNonTermCurrent;
        }
        /// <summary>
        /// Get Non Term Current DataTable
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="CONNECTION_STRING"></param>
        /// <returns></returns>
        public DataTable GetNonTermCurrentTable(int UserID, String CONNECTION_STRING)
        {
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@UserID",UserID),
            };
            //Lets get the list of all Non Term Current in a datataable
            DataTable table = SqlDBHelper.ExecuteParamerizedSelectCommand("GetNonTermCurrentTable", CommandType.StoredProcedure, CONNECTION_STRING, parameters);
            return table;
        }

        /// <summary>
        /// Update Balance
        /// </summary>
        /// <param name="Balance"></param>
        /// <param name="AccountNumber"></param>
        /// <param name="CONNECTION_STRING"></param>
        /// <returns></returns>

        public bool UpdateNonTermBalanceReceived(String AccountNumber, Double Balance, String CONNECTION_STRING)
        {

            SqlParameter[] parameter = new SqlParameter[]
            {
                new SqlParameter("@AccountNumber",AccountNumber),
                new SqlParameter("@Balance", Balance),
            };
            return SqlDBHelper.ExecuteNonQuery("UpdateNonTermBalanceReceived", CommandType.StoredProcedure, CONNECTION_STRING, parameter);
        }

    }
}
